#!/bin/sh
install_dir=/opt/wine-ce/
if [ $# -gt 0 ] ; then
    install_dir=$1
fi

echo "install directory: $install_dir"

cd wine
./configure --prefix="$install_dir" --disable-tests --enable-archs=
make -j$(nproc)
rm -rf $install_dir
make install
cd ..

rm -rf build.qemu
mkdir build.qemu && cd build.qemu
CC=gcc CC_FOR_BUILD="$CC" CXX="$CC" HOST_CC="$CC" \
LDFLAGS="-Wl,-Ttext-segment=0x100000000 -Wl,-z,max-page-size=0x1000 -Wl,-Bstatic,-lglib-2.0 -Wl,-Bdynamic" \
../qemu/configure --without-default-features --disable-fdt --disable-system --enable-ca11c0de --disable-rcu --meson=meson --target-list=x86_64-linux-user,aarch64-linux-user
ninja -j$(nproc)
strip qemu-x86_64 -o "$install_dir"/bin/qemu-x86_64
strip qemu-aarch64 -o "$install_dir"/bin/qemu-aarch64
cd ..

sh generate_scripts.sh "$install_dir"/bin